Microservices are a software development technique, and a variant of the service-oriented architecture style that structures a software application as a collection of loosely coupled services. In a microservices architecture, the loosely coupled services are fine-grained services and their communication protocols are lightweight. Decomposing an application into smaller services improves modularity, which makes the application easier to understand, develop, and test. This application decomposition parallelizes development by enabling small autonomous teams to develop, deploy, and scale their respective services independently.
Whether a software developer is building a new product or decomposing an existing monolithic application, one of the most difficult problems in adopting a microservices architecture is defining the granularity of each microservice. Defining the correct boundaries, both from the business and the technological aspect, is an error prone process that is extremely difficult to accomplish correctly. This tedious and iterative process can require significant amounts of time and money. As much as a microservices architecture allows agility and quick response to business needs, an evolving microservices architecture requires rethinking, changing the boundaries of existing components, and a process known as refactoring.
Refactoring is the process of restructuring existing computer code—changing the factoring—without changing the computer code's external behavior. Refactoring is intended to improve non-functional attributes of the computer code. Advantages of refactoring include reduced complexity and improved source-code maintainability. Typically, refactoring applies a series of standardized basic micro-refactorings, each of which is usually a tiny change in a computer program's source code that either preserves the behavior of the computer code, or at least does not modify the source code's conformance to functional requirements. Many software development environments provide automated support for performing the mechanical aspects of these basic refactorings. If done well, the refactoring of computer code may help software developers discover and correct hidden bugs or vulnerabilities by simplifying the underlying logic and eliminating unnecessary levels of complexity.
Moreover, when a developer wants to introduce a new concept into an existing system composed of several microservices, the developer needs to decide how to divide the new concept to different parts appropriate for each of the current microservices or conduct a refactoring of the system. The refactoring can generate new microservices which will include computer code for the new concept.